package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.IncomeRecordPageVO;
import com.sc.nft.entity.vo.merchantPledgeTask.AdminIncomeConfVO;
import com.sc.nft.enums.MerchantPledgeTaskIncomeTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MerchantPledgeTaskIncomeConf;
import com.sc.nft.mapper.MerchantPledgeTaskIncomeConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商户质押任务收益配置表(sc_merchant_pledge_task_income_conf)数据DAO
 *
 * @author Sun
 * @since 2023-08-24 16:16:49
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class MerchantPledgeTaskIncomeConfDao extends ServiceImpl<MerchantPledgeTaskIncomeConfMapper, MerchantPledgeTaskIncomeConf> {

    public List<MerchantPledgeTaskIncomeConf> getListByTaskId(Long merchantPledgeTaskId) {
        LambdaQueryWrapper<MerchantPledgeTaskIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskIncomeConf::getMerchantPledgeTaskId, merchantPledgeTaskId);
        return list(wrapper);
    }

    public List<AdminIncomeConfVO> getDirectIncomeListAndRewardsDetailsByTaskId(Long merchantPledgeTaskId, Long id) {
        return baseMapper.getDirectIncomeListAndRewardsDetailsByTaskId(merchantPledgeTaskId,id);
    }
    public List<AdminIncomeConfVO> getExtrapolatedIncomeListAndRewardsDetailsByTaskId(Long merchantPledgeTaskId, Long id) {
        return baseMapper.getExtrapolatedIncomeListAndRewardsDetailsByTaskId(merchantPledgeTaskId,id);
    }

    public Page<IncomeRecordPageVO> incomeRecordPage(Long userId, Integer pageNo, Integer pageSize) {
        return baseMapper.incomeRecordPage(new Page<>(pageNo, pageSize), userId);
    }

    public MerchantPledgeTaskIncomeConf getListByTaskIdAndType(Long id, MerchantPledgeTaskIncomeTypeEnum incomeType) {
        LambdaQueryWrapper<MerchantPledgeTaskIncomeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskIncomeConf::getMerchantPledgeTaskId,id);
        wrapper.eq(MerchantPledgeTaskIncomeConf::getPledgeIncomeType,incomeType);
        wrapper.last("order by id desc limit 1");
        return getOne(wrapper);
    }
}